home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4101 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  55 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Float calculations
  5. Date: 01 Feb 1996 23:32:49 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb1163249@qcd.lanl.gov>
  8. References: <4eqssf$d9q@camelot.ccs.neu.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: jason@ccs.neu.edu's message of 1 Feb 1996 17:22:23 GMT
  13.  
  14. In article <4eqssf$d9q@camelot.ccs.neu.edu> jason@ccs.neu.edu (Jason
  15. Leatherman) writes: 
  16. <snip>
  17.    Hi,
  18.  
  19.      Check out the results I get when running this simple program on a
  20.    Sparc/UNIX system, compiled with gcc:
  21.  
  22.    #include <stdio.h>
  23.  
  24.    void main()
  25.    {
  26.      float a, b;
  27.  
  28.      printf("%0.10f  %0.10f  %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
  29.  
  30.      a = 99974.0;
  31.      b = 50.0;
  32.      printf("%0.10f  %0.10f  %0.10f\n", a, b, a/b);
  33.    }
  34.  
  35.    The output is:
  36.    99974.0000000000  50.0000000000  1999.4800000000
  37.    99974.0000000000  50.0000000000  1999.4799804688
  38.  
  39.      Why do the divisions produce different results?  This is probably some
  40.    simple thing that I've forgotten, but I haven't figured it out yet.  Does
  41.    anyone know?  Note that compiling with the -ffloat-store flag didn't make
  42.    a difference.
  43.  
  44. Because neither 99974.0 not 50.0 are floats.
  45.  
  46. Cheers
  47. Tanmoy
  48. --
  49. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  50. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  51. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  52. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  53. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  54. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  55.